

<page-demo>
  <p>
    用户:<input type="text" ref="username">
  </p>
  <p>
    密码:<input type="password" ref="password">
    <validator ref="validPassword" for="{[refs.username,refs.password]}" rule="req">用户名,密码不能为空</validator>
    <br>
    新密码:<input type="password" ref="password2">
    <validator ref="validCPassword" for="{[refs.password,refs.password2]}" rule="req,match">两组密码要一致，且不能为空</validator>
  </p>
  <p>
    <select onchange="{ev.checkSelect}" ref="num">
      <option value="{n}" each="{n in [0,1,2,3,4]}">{n}</option>
    </select>
    <validator ref="validNum" for="{[refs.num]}" rule="+int">数字必须正整数</validator>
  </p>
  <p>
    <input type="text" ref="float" oninput="{ev.checkFloat}" placeholder="浮点数">
    <validator ref="validFloat" for="{[refs.float]}" rule="+float.2">必须是正浮点数，只保留2位小数</validator>
  </p>
  <p><ui-button color="green" onclick="{ev.check}">校验</ui-button></p>
  <script>
    var tag = this;
    tag.ev = {
      checkFloat: function(){
        tag.refs.validFloat.check();
      },
      checkSelect: function(){
        tag.refs.validNum.check();
      },
      check: function(){
        if([
          tag.refs.validPassword.check(),
          tag.refs.validNum.check(),
          tag.refs.validFloat.check(),
          tag.refs.validCPassword.check()
        ].indexOf(false) < 0){
          console.log('表单正确')
        }
      }
    };
    tag.fn = {};
    tag.on('mount', function(){
    });

  </script>
</page-demo>
